//
//  GCDGroup.m
//  MyFunctionDemo
//
//  Created by Ting Han on 2017/8/28.
//  Copyright © 2017年 Ting Han. All rights reserved.
//

#import "GCDGroup.h"

@interface GCDGroup ()

@property (nonatomic, strong) dispatch_group_t dispatchGroup;

@end
@implementation GCDGroup

- (instancetype)init
{
    if (self = [super init]) {
        self.dispatchGroup = dispatch_group_create();
    }
    return self;
}

- (void)wait
{
    dispatch_group_wait(self.dispatchGroup, DISPATCH_TIME_FOREVER);
}

- (void)enter
{
    dispatch_group_enter(self.dispatchGroup);
}

- (void)leave
{
    dispatch_group_leave(self.dispatchGroup);
}

- (BOOL)wait: (NSTimeInterval)delay
{
    return dispatch_group_wait(self.dispatchGroup, delay * NSEC_PER_SEC) == 0;
}

@end
